package com.cutJar.frame;

import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JTextField;

import com.awt.annotation.Control;
import com.awt.control.AbstractControl;
import com.cutJar.core.FirstStep;
import com.cutJar.core.LastStep;
import com.cutJar.core.NextStep;
import com.gui.DComp.DProgressBar_G;
import com.gui.typeStyle.DefaultTextArea;
import com.stream.Stream.Resource;
/**
 * <b>cutJar界面类</b>
 * <p>
 * @author 威
 * <br>2018年4月29日 下午5:42:12
 * @see com.awt.control.AbstractControl
 * @since 1.0
 */
@Control
public class CutJarFrame extends AbstractControl{
	private boolean selectFlag;		//选择默认
	private JTextField jrePath;		//jre目录
	private JTextField jarName;		//jar路径
	private JTextField cutName;		//要剪切的包名称
	private DefaultTextArea showInfo;		//显示信息文本框，不可输入
	private DProgressBar_G bar;
	
	public CutJarFrame(){
		super();
		selectFlag = true;
	}
	
	@Override
	protected void execute() {
		System.out.println("start program!");
		jrePath = (JTextField) this.getComponentByName("jrePathText");
		jarName = (JTextField) this.getComponentByName("jarName");
		cutName = ((JTextField) getComponentByName("cutNameText"));
		showInfo = (DefaultTextArea) getComponentByName("showInfo");
		
		String imgPath = Resource.getResourceToString("img", "barimg.png");
		ImageIcon img = new ImageIcon(imgPath);
		bar = new DProgressBar_G(img);
		add("progressbar", (JComponent) bar.getComponent());
		bar.setMargin(0, 0);
		bar.setOrigSize(450, 6);
		bar.slideTo(450);
	}
	public void selectRadio(MouseEvent e){
		selectFlag = selectFlag ? false : true;
		cutName.setEnabled(selectFlag);
	}
	
	/*==================按钮操作事件=====================*/
	public void reset(MouseEvent e){
		jrePath.setText("");
		jarName.setText("");
		cutName.setText("");
	}
	public void doStart(MouseEvent e){
		String jrePathStr = jrePath.getText();
		String jarPathStr = jarName.getText();
		String cutNameStr = cutName.getText();
		if(!jrePathStr.equals("") 
				&& !jarPathStr.equals("") 
				&& (!cutNameStr.equals("") || !selectFlag)){
			System.out.println("start");
			FirstStep step1 = new FirstStep();
			NextStep step2 = new NextStep();
			LastStep step3 = new LastStep();
			step1.doStart(jrePathStr+
					java.io.File.separator+
					"bin",
					jarPathStr);
			/*if(selectFlag){
				step2.defiStart(cutNameStr, 
						jrePathStr+
						java.io.File.separator+
						"lib");
				step3.doDefiStart(cutNameStr);
			}else{
				step2.doMainStart(jrePathStr+
						java.io.File.separator+
						"lib");
				step3.doMainStart();
			}*/
		}else{
			System.out.println("必要信息不能为空");
		}
	}
	public void selectJrePath(MouseEvent e){
		System.out.println("selectJrePath");
	}
	public void selectJarPath(MouseEvent e){
		System.out.println("selectJarPath");
	}
	/*==================按钮操作事件=====================*/
}
